function init(){
    update_task_list();
    setTimeout(function() {
      console.log("000");
    },
    5000);
}

function onAlert() {
    console.log("onAlert method");
    alert("This is a alert sample from html");
}

function mend_task(id){
    Android.mend_task(id);
}

function change_task_status(id,hits,new_status){

    var ret = confirm(hits + " ID:" + id + ", Are you sure?");
    if(ret)
    {
        Android.update_task_status(id,new_status);
        var content_divs = document.getElementsByClassName('task_item');
        for(var i=0;i<content_divs.length;i++)
        {
            if (content_divs[i].getAttribute('value') == id)
            {
                //removeElement(content_divs[i]);

                var $this=$(content_divs[i]);

                $this.animate({opacity:0.0,paddingLeft:'+=180'},1000,'swing',function(){$this.remove();});
                break;
            }
        }

    }
}

function clean_task_list() {
    var content_div = document.getElementById('content_list');
    content_div.innerHTML = "";
}

function add_item(id,title,content,date,status) {

    var hits = "";
    if(status==0)
        hits="Set completed";
    else
        hits="Set incompleted";

    var content_div = document.getElementById('content_list');

    var task_date = $("<div class='task_head_bar_title'></div>");
    task_date.click(function(){mend_task(id)});
    task_date.text(date);

    var task_status_bt = $("<div class='task_head_bar_del_bt'></div>");
    task_status_bt.click(function(){change_task_status(id,hits,status=="0"?1:0)});
    task_status_bt.text(hits);

    var task_title = $("<div class='task_title'></div>");
    task_title.append($("<pre></pre>").html(title));

    var task_content = $("<div class='task_content'></div>");
    //task_content.text(content);
    task_content.append($("<pre></pre>").html(content));

    var task_head_bar = $("<div class='task_head_bar'></div>");
    task_head_bar.append(task_date,task_status_bt);

    var task_item = $("<div class='task_item'></div>");
    task_item.attr("value",id);

    task_item.append(task_head_bar,task_title,task_content);

    $(content_div).append(task_item);
}

function update_task_list()
{
    clean_task_list();
    var done = getQueryString('done');
    if(done==null)
        done=0;
    Android.update_task_list('status='+done);
}
